﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="Tool.aspx.cs" Inherits="MonitorPlan.Admin.Tool" %>
<%@ MasterType VirtualPath="~/Admin/AdminMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Tool Management</title>
     <script>
        $(document).ready(function () {
            $("a#btnTool").css("background", "#CCC");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <%-- sqldatasource to get location name --%>
            <asp:SqlDataSource ID="dsLocation" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select locationid, locationname from location where isdeleted=0"></asp:SqlDataSource>
            <%-- sqldatasource to get tools --%>
            <asp:SqlDataSource ID="dsTool" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select * from tool where isdeleted=0"></asp:SqlDataSource>
            <%-- sqldatasource to get house name --%>
            <asp:SqlDataSource ID="dsHouse" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                  SelectCommand="select houseid, housename from house where isdeleted=0"></asp:SqlDataSource>
            <%-- sqldatasource to get room name --%>
            <asp:SqlDataSource ID="dsRoom" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select roomid, roomname from room where isdeleted=0"></asp:SqlDataSource>
             <%-- top menu for view and add new tool --%>
              <ul class="nav nav-pills action-buttons">
                <li><asp:LinkButton ID="btnView" runat="server" OnClick="btnView_Click">
                    <i class="icon icon-view"></i>&nbsp;View</asp:LinkButton></li>
                 <li>
                     <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">
                         <i class="icon icon-add"></i>&nbsp;Add New
                     </asp:LinkButton>
                 </li>
            </ul>
             <%-- multiview for insert, view, edit and detail view for tools --%>
            <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
                <asp:View ID="vTool" runat="server">
                    <h5 class="text-info">View Tools</h5>
                    <asp:Repeater ID="rp1" runat="server" DataSourceID="dsTool" OnItemCommand="rp1_ItemCommand">
                        <HeaderTemplate>
                             <table class="table table-condensed table-striped table-hover">
                                <tr>
                                    <th>Tool Id</th>
                                    <th>Tool Type</th>
                                    <th>Key On</th>
                                    <th>Key Off</th>
                                 <%--   <th>Room Id</th>--%>
                                    <th>House Id</th>
                                    <th>Actions</th>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                             <tr>
                                <td><%# Eval("toolid") %></td>
                                <td><%# Eval("tooltype") %></td>
                                <td><%# Eval("keyon") %></td>
                                <td><%# Eval("keyoff") %></td>
                                 <%--<td><%# Eval("roomid") %></td>--%>
                                 <td><%# Eval("houseid") %></td>
                                <td>
                                    <%-- the command button to edit, delete and view detail for each room --%>
                                    <asp:LinkButton ID="btnDetail" runat="server"
                                        CommandName="detail" CommandArgument='<%# Eval("toolid") %>'>
                                        Detail</asp:LinkButton>&nbsp;
                                     <asp:LinkButton ID="btnEdit" runat="server" 
                                        CommandName="edit" CommandArgument='<%# Eval("toolid") %>'>
                                        Edit</asp:LinkButton>&nbsp;
                                    <asp:LinkButton ID="btnDelete" runat="server"
                                        CommandName="delete" CommandArgument='<%# Eval("toolid") %>' OnClientClick="return confirm('You want to delete it?');">
                                        Delete
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                </asp:View>

                <%-- view to add new tool --%>
                
                <asp:View ID="vNewTool" runat="server">
                    <asp:SqlDataSource ID="sdToolType" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>" 
                        SelectCommand="select devicetypeid, devicetypename from devicetype where isdeleted=0">

                    </asp:SqlDataSource>

                    <h5 class="text-info">Add New Tool</h5>
                    <label for="ddlType">Tool Type</label>
                    <asp:DropDownList ID="ddlType" runat="server" AutoPostBack="false" Width="314" DataSourceID="sdToolType"
                        DataTextField="devicetypename" DataValueField="devicetypename">
                       
                    </asp:DropDownList><br />
                    <asp:TextBox ID="txtToolName" runat="server" Width="300" placeholder="Tool Name"></asp:TextBox>
                    <br />
                    <asp:TextBox ID="txtKeyOn" runat="server" Width="140" placeholder="Key To On"></asp:TextBox>
                    <asp:TextBox ID="txtKeyOff" runat="server" Width="140" placeholder="Key To Off"></asp:TextBox>
                    <label for="ddlLocationName">Location Name</label>
                    <asp:DropDownList ID="ddlLocationName" runat="server" Width="314" AutoPostBack="true"
                         DataSourceID="dsLocation" DataTextField="locationname" DataValueField="locationid" OnSelectedIndexChanged="ddlLocationName_SelectedIndexChanged"></asp:DropDownList>
                    <label for="ddlHouseName">House Name</label>
                    <asp:DropDownList ID="ddlHouseName" runat="server" Width="314" DataSourceID="dsHouse"
                         DataTextField="housename" DataValueField="houseid" AutoPostBack="true" OnSelectedIndexChanged="ddlHouseName_SelectedIndexChanged">
                    </asp:DropDownList>
                  <%--  <label for="ddlRoomName">Room Name</label>
                    <asp:DropDownList ID="ddlRoomName" runat="server" Width="314" AutoPostBack="false"
                         DataSourceID="dsRoom" DataTextField="roomname" DataValueField="roomid"></asp:DropDownList>--%>
                    <br />
                    <asp:TextBox ID="txtToolDesc" runat="server" TextMode="MultiLine" placeholder="Description"
                         Width="300" Height="60"></asp:TextBox>
                    <br />

                    <%-- The button to save, cancel and go back --%>
                      <asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-primary btn-small" OnClick="btnSave_Click">
                        <i class="icon-ok-circle icon-white"></i> Save</asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancel_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <asp:LinkButton ID="btnClose" runat="server" CssClass="btn btn-success btn-small" OnClick="btnClose_Click">
                        <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                    <br /><br />
                    <div runat="server" id="actionSms"></div>
                 </asp:View>
                
            </asp:MultiView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
